package tk.hoopy.zedtown;

import tk.hoopy.zedtown.graphics.GameWindow;
import tk.hoopy.zedtown.input.InputManager;
import tk.hoopy.zedtown.input.KeyboardInput;
import tk.hoopy.zedtown.levels.LevelManager;

public class GameSession {
	
	private static InputManager inputManager;
	private static GameWindow gameWindow;
	private LevelManager levelManager;
	
	private int x = 0, y = 0;
	
	public static void SetupConstantObjects(InputManager im, GameWindow gw) {
		inputManager = im; gameWindow = gw;
	}
	
	public GameSession(LevelManager levelman) {
		levelManager = levelman;
		gameWindow.SetPositionX(0);
		gameWindow.SetPositionY(0);
	}
	
	public void PerformEntityLogic() {
		
	}
	
	public void PerformLevelLogic() {
		if(inputManager.GetKeyState(KeyboardInput.UP)) {
			y-=2;
		} else if(inputManager.GetKeyState(KeyboardInput.DOWN)) {
			y+=2;
		}
		
		if(inputManager.GetKeyState(KeyboardInput.LEFT)) {
			x-=2;
		} else if(inputManager.GetKeyState(KeyboardInput.RIGHT)) {
			x+=2;
		}
		
		if(x<0){x=0;}if(x>levelManager.GetCurrentLevelSize()*150 - gameWindow.getWidth()){x=levelManager.GetCurrentLevelSize()*150 - gameWindow.getWidth();}
		if(y<0){y=0;}if(y>levelManager.GetCurrentLevelSize()*150 - gameWindow.getHeight()){y=levelManager.GetCurrentLevelSize()*150 - gameWindow.getHeight();}
		
		gameWindow.SetPositionX(x);
		gameWindow.SetPositionY(y);
		
	}
	
	public void Draw() {
		levelManager.BuildMap();
	}
	
}
